import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../generated/l10n.dart';
import '../main.dart';
import '../utils/CommUtils.dart';

/**
 * 游戏失败
 */

class GameFileText extends Dialog {
  int currentScore = 0; //当前分数
  Uint8List? gamebg; //游戏背景截图
  CallBack? callback; //点击新游戏回调
  int type; //1经典，2每日
  GameFileText(
      {required this.currentScore,
      required this.gamebg,
      required this.callback,
      required this.type});
  @override
  Widget build(BuildContext context) {
    double size = CommUtils.getWidth(context);
    double hight = CommUtils.getHeight(context);
    return Material(
      type: MaterialType.transparency,
      child: Container(
        width: CommUtils.getISWidth(size, hight) ? hight * 0.7 : size * 0.85,
        margin: EdgeInsets.only(top: hight * 0.15),
        //    width: CommUtils.getWidth(context) - ScreenUtil().setWidth(20),
        child: Column(
          children: [
            CommUtils.getTextGame(
              context,
              30,
              S.of(context).almost_,
              Color(0xfff6e8f9),
              Color(0Xffb68bcb),
            ),
            Container(
                margin: EdgeInsets.only(
                    left: ScreenUtil().setWidth(15),
                    right: ScreenUtil().setWidth(15)),
                decoration: BoxDecoration(
                  image: DecorationImage(
                      image: AssetImage('assets/images/bg_seting.png'),
                      fit: BoxFit.fill),
                ),
                child: Padding(
                  padding: EdgeInsets.only(
                      left: hight * 0.04,
                      right: hight * 0.03,
                      top: hight * 0.09,
                      bottom: hight * 0.08),
                  child: Column(
                    children: [
                      Container(
                        width: double.infinity,
                        height: hight * 0.4,
                        decoration: BoxDecoration(
                          image: DecorationImage(
                              image: AssetImage('assets/images/middle.png'),
                              fit: BoxFit.fill),
                        ),
                        child:
                            gamebg != null ? Image.memory(gamebg!) : Text(""),
                        //
                      ),
                      SizedBox(
                        height: hight * 0.02,
                      ),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
//关闭本页面
                          GestureDetector(
                              onTap: () {
                                //因为有3个弹窗，
                                Navigator.pop(context);
                                Navigator.pop(context);
                                Navigator.pop(context);
                              },
                              child: Image.asset(
                                  'assets/images/button_back.png',
                                  height: hight * 0.06,
                                  fit: BoxFit.contain)),

//新游戏按钮
                          GestureDetector(
                            onTap: () {
                              //因为有两个弹窗，
                              Navigator.pop(context);
                              Navigator.pop(context);
                              if (type == 2) {
                                callback?.call(1);
                              }
                            },
                            child: Container(
                               height: hight*0.06,
                                width: hight * 0.15,
                                decoration: BoxDecoration(
                                  image: DecorationImage(
                                    image: AssetImage(
                                        'assets/images/new_game.png'),
                                    fit: BoxFit.fill,
                                  ),
                                ),
                                alignment: Alignment.center,
                                child: Padding(
                                    padding: EdgeInsets.only(
                                        top: 5, bottom: 5, right: 5, left: 5),
                                    child: CommUtils.getTextGame(
                                      context,
                                      15,
                                      S.of(context).retry_,
                                      Color(0xffe7f9c6),
                                      Color(0Xff5afddd),
                                    ))),
                          ),
                        ],
                      ),
                    ],
                  ),
                )),
          ],
        ),
      ),
    );
  }
}
